from apps.oms.hawkeye.services.scheduler import CronJobManager
from apps.oms.hawkeye.models import HawkeyeJob


manager = CronJobManager()


def start(job_id, dept_belong_id):
    """开始执行"""
    job = HawkeyeJob.objects.get(id=job_id)

    manager.add_job(
        job_id,
        plugin=job.plugin.file.path,
        hosts=job.hosts.all(),
        params=job.params,
        cron=job.cron,
        dept_belong_id=dept_belong_id,
    )


def stop(job_id):
    """停止执行"""
    manager.remove_job(job_id)
